Skip to content

Unify first parameter name to path_or_io across methods#358

Merged
kou merged 4 commits intoruby:mainfrom
alstrocrack:docs/update_method_comments
May 7, 2026
Merged

Unify first parameter name to path_or_io across methods#358
kou merged 4 commits intoruby:mainfrom
alstrocrack:docs/update_method_comments

Conversation

@alstrocrack
Copy link
Copy Markdown
Contributor

@alstrocrack alstrocrack commented May 4, 2026

Overview

Previously, the first parameter name was inconsistent across methods and their RDoc comments, with names such as path, source, and filename_or_io used interchangeably despite referring to the same concept:
a file path or an IO object.

This change aligns all class methods to use path_or_io. This more accurately conveys that the argument accepts either a file path or an IO object.

Reference

@alstrocrack alstrocrack changed the title Update methods comment Unify first parameter name to filename_or_io across methods May 4, 2026
@alstrocrack alstrocrack marked this pull request as ready for review May 4, 2026 07:25
@kou
Copy link
Copy Markdown
Member

kou commented May 4, 2026

Hmm. Let's use path_or_io not filename_or_io.

@alstrocrack
Copy link
Copy Markdown
Contributor Author

Thank you for your suggestion.
I’ve changed filename_or_io to path_or_io across the repository.
Could you please take a look?

@kou
Copy link
Copy Markdown
Member

kou commented May 6, 2026

Could you also update the PR title and description?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to standardize the first parameter name across CSV class methods to better communicate that callers may pass either a file path or an IO-like object, and to align the corresponding RDoc wording.

Changes:

  • Renames the first parameter for CSV.foreach, CSV.read, CSV.readlines, and CSV.table to a unified name.
  • Renames CSV.open’s first parameter and the related private helper parameter to match the unified name.
  • Updates related RDoc text to reference the unified parameter name.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/csv.rb
Comment on lines +1389 to +1391
def foreach(path_or_io, mode="r", **options, &block)
return to_enum(__method__, path_or_io, mode, **options) unless block_given?
open(path_or_io, mode, **options) do |csv|
Comment thread lib/csv.rb
Comment on lines +1647 to 1652
def open(path_or_io, mode="r", **options)
# wrap a File opened with the remaining +args+ with no newline
# decorator
file_opts = {}
may_enable_bom_detection_automatically(filename_or_io,
may_enable_bom_detection_automatically(path_or_io,
mode,
Comment thread lib/csv.rb
Comment on lines +1922 to +1931
def read(path_or_io, **options)
open(path_or_io, **options) { |csv| csv.read }
end

# :call-seq:
# CSV.readlines(source, **options)
#
# Alias for CSV.read.
def readlines(path, **options)
read(path, **options)
def readlines(path_or_io, **options)
read(path_or_io, **options)
Comment thread lib/csv.rb
Comment on lines +1949 to +1956
def table(path_or_io, **options)
default_options = {
headers: true,
converters: :numeric,
header_converters: :symbol,
}
options = default_options.merge(options)
read(path, **options)
read(path_or_io, **options)
@alstrocrack alstrocrack changed the title Unify first parameter name to filename_or_io across methods Unify first parameter name to path_or_io across methods May 6, 2026
@alstrocrack alstrocrack requested a review from Copilot May 6, 2026 07:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread lib/csv.rb
Comment on lines +1389 to +1391
def foreach(path_or_io, mode="r", **options, &block)
return to_enum(__method__, path_or_io, mode, **options) unless block_given?
open(path_or_io, mode, **options) do |csv|
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

lib/csv.rb:1940

  • The :call-seq: for table still uses source while the method signature is now table(path_or_io, **options). Since the PR’s goal is to unify the first parameter name, the :call-seq: should also be updated to path_or_io to keep docs consistent.
    # :call-seq:
    #   CSV.table(source, **options)
    #
    # Calls CSV.read with +source+, +options+, and certain default options:
    # - +headers+: +true+
    # - +converters+: +:numeric+
    # - +header_converters+: +:symbol+

Comment thread lib/csv.rb
Comment on lines 1584 to 1586
# * This method optionally accepts an additional <tt>:encoding</tt> option
# that you can use to specify the Encoding of the data read from +path+ or +io+.
# that you can use to specify the Encoding of the data read from +path_or_io+.
# You must provide this unless your data is in the encoding
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think this should be fixed, but it shouldn’t be done in this PR.

Comment thread lib/csv.rb
Comment on lines 1921 to +1923
# CSV.read(path, headers: true) # => #<CSV::Table mode:col_or_row row_count:4>
def read(path, **options)
open(path, **options) { |csv| csv.read }
def read(path_or_io, **options)
open(path_or_io, **options) { |csv| csv.read }
Comment thread lib/csv.rb Outdated
Comment on lines +1927 to +1931
# CSV.readlines(source, **options)
#
# Alias for CSV.read.
def readlines(path, **options)
read(path, **options)
def readlines(path_or_io, **options)
read(path_or_io, **options)
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@alstrocrack
Copy link
Copy Markdown
Contributor Author

I fixed this PR’s title, description, and all the suggestions from GitHub Copilot. Could you please check it again?

@kou kou merged commit 19c7649 into ruby:main May 7, 2026
62 of 72 checks passed
@kou
Copy link
Copy Markdown
Member

kou commented May 7, 2026

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants